package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ProductCatalog;
import cn.wolfcode.trip.base.mapper.ProductCatalogMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author by mycp
 * @Classname ProductCatalogServiceImpl
 * @Description TODO
 * @Date 2018/11/14 15:39
 */
@Service
public class ProductCatalogServiceImpl implements IProductCatalogService {
    @Autowired
    private ProductCatalogMapper productCatalogMapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<ProductCatalog> list = productCatalogMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveorUpdate(ProductCatalog productCatalog) {
        if (productCatalog.getId() == null) {
            // 保存操作
            productCatalogMapper.insert(productCatalog);
        } else {
            // 更新操作
            productCatalogMapper.updateByPrimaryKey(productCatalog);
        }
    }

    @Override
    public List<ProductCatalog> selectEnable() {
        return  productCatalogMapper.selectEnable();
    }

    @Override
    public List<ProductCatalog> getCatalogs(Long state) {
        return productCatalogMapper.getCatalogs(state);
    }

    @Override
    public PageInfo getProducts(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<ProductCatalog> list = productCatalogMapper.queryForProducts(qo);
        return new PageInfo(list);
    }
}
